package org.meb.speedway.model.registry;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.persistence.Version;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import org.hibernate.annotations.ForeignKey;

@Entity
@Table(name = "t_team_rider_history", uniqueConstraints = @UniqueConstraint(columnNames = {
		"team_id", "rider_id", "year" }))
@Getter
@Setter
@ToString(of = { "year", "team", "rider" })
public class TeamRiderHistory implements Serializable {

	private static final long serialVersionUID = 4696046443855134724L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;

	@Version
	private Long version;

	@Column(nullable = false)
	private Integer year;

	@ManyToOne(optional = false, fetch = FetchType.EAGER)
	@JoinColumn(name = "team_id")
	@ForeignKey(name = "TRHI_TEAM_FK")
	private Team team;

	@ManyToOne(optional = false, fetch = FetchType.EAGER)
	@JoinColumn(name = "rider_id")
	@ForeignKey(name = "TRHI_RIDR_FK")
	private Rider rider;
}